var app = getApp()

Component({
  data: {
    top: 40,
    width: 100,
    height: 30,
  },
  properties: {
    // 显示隐藏
    show: {
      type: Boolean,
      value: true
    },
    // 胶囊背景 dark.深色 white.白色
    bg: {
      type: String,
      value: 'white'
    },
  },

  ready() {
    // 系统屏幕位置信息
    const systemInfo = wx.getSystemInfoSync()
    // console.log('systemInfo', systemInfo)

    // 胶囊位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
    // console.log('menuButtonInfo', menuButtonInfo)

    // 单位间距（胶囊距屏幕右侧的距离）
    const dp = systemInfo.screenWidth - menuButtonInfo.right
    this.setData({
      dp,
    })

    // 胶囊位置
    this.setData(Object.assign(this.data, menuButtonInfo))

    const pageLength = getCurrentPages().length
    if (pageLength > 1) {
      this.setData({
        btnImg: "https://assets.mhblog.cn/mhblog/icon/back-left.png",
        showHome: false
      })
    } else {
      this.setData({
        btnImg: "https://assets.mhblog.cn/mhgallery/icon/homeblack1.png",
        showHome: true
      })
    }

  },

  methods: {
    onBack() {
      const pageLength = getCurrentPages().length
      if (pageLength > 1) {
        wx.navigateBack()
      } else {
        wx.reLaunch({
          url: "/packagedouyin/pages/list/list"
        })
      }
    }
  }
});